package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dto.Member;
import schoolDAO.MemberDAO;
//
//public class RegisterServlet extends HttpServlet {
//
//	protected void doGet(HttpServletRequest req,HttpServletResponse resp)	
//			throws ServletException, IOException{
//		String mId=req.getParameter("mId");
//		String mName=req.getParameter("mName");
//		String mPassword=req.getParameter("mPassword");
//		String mSuper=req.getParameter("mSuper");
//		Member m=new Member();
//		m.setmId(mId);
//		m.setmName(mName);
//		m.setmPassword(mPassword);	
//		m.setmSuper(Integer.parseInt(mSuper));
//		MemberDAO md=new MemberDAO();
//        boolean flag=md.insert(m);
//	
//        if(flag)
//        	resp.sendRedirect(req.getContextPath()+"/index.html");
//        else
//        	resp.sendRedirect(req.getContextPath()+"/register.html");
//	
//	}
//}


//package cn.edu.lingnan.servlet;
//
//import java.io.IOException;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import cn.edu.lingnan.dao.studentDAO;
//import cn.edu.lingnan.dto.Student;

public class RegisterServlet extends HttpServlet {
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req,resp);
	}
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		    String mId = req.getParameter("mId");
			String username = req.getParameter("username");
			String password = req.getParameter("password");
			int mSuper = Integer.parseInt(req.getParameter("mSuper"));
			
			MemberDAO md = new MemberDAO();
			Member m = new Member();
			m.setmId(mId);
			m.setmName(username);
			m.setmPassword(password);
			m.setmSuper(mSuper);
			boolean flag = md.insert(m);
			if(flag){
				resp.sendRedirect(req.getContextPath()+"/admin/allMember.jsp");
			}else{
				resp.sendRedirect(req.getContextPath()+"/error.html");
			}		
	}

}
